﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;



namespace Ebada.Modules.Document
{
    /// <summary>
    /// 库位信息编辑
    /// </summary>
    public partial class frmDocumentPositionEdit : FormBase, IPopupFormEdit 
    {
        SortableSearchableBindingList<mOrg> m_OrgID = new SortableSearchableBindingList<mOrg>();

        public frmDocumentPositionEdit()
        {
            InitializeComponent();
        }

        void btnPostDic_Click(object sender, EventArgs e)
        {
            //编写选择单位代码

            //FrmDictionary frmPostDic = new FrmDictionary("");
           
            //if (frmPostDic.ShowDialog() == DialogResult.OK)
            //{
            //    PositionDictionary postDic = frmPostDic.NowPostDic;
            //    this.cltPost.Properties.KeyValue = postDic.Post_ID;
            //}
        }
        void dataBind() 
        {

            this.txtKwName.DataBindings.Add("EditValue", rowData, "PositionName");
            this.txtKwJb.DataBindings.Add("EditValue", rowData, "PositionLevel");
            //this.txtGldwbs.DataBindings.Add();
            this.cltOrgID.DataBindings.Add("EditValue", rowData, "Org_ID");
        }
        #region IPopupFormEdit Members
        private DocumentPosition rowData = null;

        public object RowData 
        {
            get 
            {
                return rowData;
            }
            set
            {
                if (value == null) return;
                if (rowData == null) 
                {
                    this.rowData = value as DocumentPosition;
                    this.InitComboBoxData(this.rowData.Org_ID);
                    dataBind();
                } else {
                    ConvertHelper.CopyTo<DocumentPosition>(value as DocumentPosition, rowData);
                }
            }
        }

        #endregion

       
        private void InitComboBoxData(string OrgId)
        {
            this.m_OrgID.Clear();
            this.m_OrgID.Add(ClientHelper.PlatformSqlMap.GetList<mOrg>(" WHERE 2>1"));
            this.SetComboBoxData(this.cltOrgID, "cnName", "Org_ID", "请选择", "单位代码", this.m_OrgID);

            //if (null != cityCode && cityCode.Trim().Length > 0)
            //    this.cltCity.Properties.KeyValue = cityCode;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="displayMember"></param>
        /// <param name="valueMember"></param>
        /// <param name="nullTest"></param>
        /// <param name="cnStr"></param>
        /// <param name="post"></param>
        public void SetComboBoxData(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, SortableSearchableBindingList<mOrg> post) {
            comboBox.Properties.Columns.Clear();
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
            comboBox.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(valueMember, "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(displayMember, cnStr)});
        }

       

        private void cltOrgID_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index==1)
            {
                Ebada.Modules.Vehicle.frmOrgSelector2 frm = new Ebada.Modules.Vehicle.frmOrgSelector2();
                frm.IntionDataAll();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    cltOrgID.Text = frm.SelectObj.cnName;
                }
            }
           
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtKwName.Text.Length == 0)
            {
                MessageBox.Show("位置名称不能为空!");
                return;

            }
            else
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        
       
    }
}